package com.talent.common.model;

import com.talent.common.enums.ResponseEnum;
import com.talent.common.enums.TalentResponse;
import lombok.Data;

/**
 * @ClassName：ResponseEnum
 * @Author: hszhou
 * @Date: 2024/10/21 13:35
 * @Description: 统一返回
 */
@Data
public class TalentResult<T>{


    private int code;
    private boolean success;
    private String message;
    private T data;

    public TalentResult(){
    }

    public TalentResult(int code, String message, T data,boolean success) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.success = success;
    }


    /**
     * 成功
     */
    public static <T> TalentResult<T> success() {
        return success(null);
    }

    /**
     * 成功
     */
    public static <T> TalentResult<T> success(T data) {
        TalentResult<T> responseResult = new TalentResult<>();
        responseResult.setCode(ResponseEnum.SUCCESS.getCode());
        responseResult.setMessage(ResponseEnum.SUCCESS.getMessage());
        responseResult.setData(data);
        responseResult.setSuccess(true);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(TalentResponse res) {
        TalentResult<T> responseResult = new TalentResult<>();
        responseResult.setCode(res.getCode());
        responseResult.setMessage(res.getMessage());
        responseResult.setData(null);
        responseResult.setSuccess(false);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(Integer code, String message) {
        TalentResult<T> responseResult = new TalentResult<>();
        responseResult.setCode(code);
        responseResult.setMessage(message);
        responseResult.setData(null);
        responseResult.setSuccess(false);
        return responseResult;
    }

    /**
     * 失败
     */
    public static <T> TalentResult<T> error(String message) {
        TalentResult<T> responseResult = new TalentResult<>();
        responseResult.setCode(ResponseEnum.ERROR.getCode());
        responseResult.setMessage(message);
        responseResult.setData(null);
        responseResult.setSuccess(false);
        return responseResult;

    }


}
